﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "选课管理 - 学生课表调整");

		termId = event.getArg("TID");

		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");

		studentId = event.getArg("STU");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		propertyAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
		
		currentTab = event.getArg("TabID", "labStudent");
		
		targetArgs = structNew();
		passArgs = structNew();
		
		opArgs = structNew();
		
		if ( len(studentId) ) {
			structInsert( targetArgs, "STU", studentId );
		}
		if ( len(termId) ) {

			structInsert( targetArgs, "TID", termId );
			structInsert( passArgs, "TID", termId );
			
			structInsert( opArgs, "TID", termId );

			/* 搜索学生档案 */
			keyword = event.getArg("Keywords", studentId);
		
			rs_student = queryNew("stu_id");
		
			if ( len(keyword) ) {

				sql = "	SELECT
							stu.stu_id,stu.stu_name,ss.student_prop,
							(SELECT t_class.cls_name FROM t_class WHERE t_class.cls_id =  stu.cls_id ) cls_name 
						FROM
							t_student stu
							INNER JOIN t_student_status ss ON ss.stu_id = stu.stu_id
						WHERE
							stu.stu_id LIKE :condition 
							OR
							stu.stu_name LIKE :condition 
						ORDER BY
							stu.stu_name";
							
				queryObj = new Query(datasource = application.dnsSlave, maxRows = 60);
				queryObj.addParam(name = "condition", value = keyword & "%", cfsqltype = "cf_sql_varchar");
				rs_student = queryObj.execute(sql = sql).getResult();

			}
		
		}

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('taskClass', opArgs)#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学任务</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 courseTable"></i>调整指定学生选课记录
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="create">
				
				<cfif termId eq "">
					<!-- termSelector -->
					<cfoutput>#event.getArg("termSelector")#</cfoutput>
					<!-- /termSelector -->
				</cfif>
				
				<cfif len(termId)>

					<div class="UItab">
						<div class="tabLables">
							<span <cfif currentTab eq "labStudent">class="active"</cfif> id="labStudent" tabTarget="Student">查找学生</span>
							<cfif len(studentId)>
								<span <cfif currentTab eq "labChooseTable">class="active"</cfif> id="labChooseTable" tabTarget="ChooseTable">调整学生选课记录</span>
								<span <cfif currentTab eq "labCourseTable">class="active"</cfif> id="labCourseTable" tabTarget="CourseTable">查看学生课表</span>
							</cfif>
						</div>
					</div>
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
						
							/* init Tab */
							$("div.tabContent").hide();
							$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
							$("div.tabLables > span").click(function(){
								var $targetID = $(this).attr("tabTarget");
								
								$("div.tabLables span").removeClass("active");
								$(this).addClass("active");
							
								$("div.tabContent").not('[id="' + $targetID + '"]').hide();
								$("div.tabContent#" + $targetID).show();
							});
						
						});
					
						// -->
						//]]>
					</script>
				
					<div id="Student" class="tabContent">
				
						<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('modifyStudentCourse', opArgs)#</cfoutput>">
							<input type="hidden" name="TabID" value="labStudent" />
						
							<div class="label">
								<b>学号或姓名</b>
								<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
							</div>
							<hr/>
							<div class="lable">
								<input class="button1" type="submit" value="搜索" />
							</div>
						</form>
					
						<cfif rs_student.recordCount>
						
							<cfset structInsert( passArgs, "TabID", "labChooseTable", true ) />

							<div class="clearfix">
								<div class="UICardTable">
                                    <cfloop query="rs_student">
									
										<cfset structInsert(passArgs, "STU", rs_student.stu_id, true) />
										<cfset propertyAdvice.parseProperty(rs_student.student_prop) />
									
										<dl <cfif not propertyAdvice.getInSchool()>class="disabled"</cfif>>
											<dt>
												<a href="<cfoutput>#buildURL('modifyStudentCourse', passArgs)#</cfoutput>">
													<em class="people"><!--imgholder--></em>
													<dd>
														<h3><cfoutput>#rs_student.stu_name#</cfoutput> - <cfoutput>#rs_student.cls_name#</cfoutput></h3>
														<p><cfoutput>#rs_student.stu_id#</cfoutput></p>
													</dd>
												</a>
											</dt>
										</dl>
									</cfloop>					
								</div>
							</div>
					
						</cfif>
				
					</div>
				
					<div id="ChooseTable" class="tabContent">
					
						<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton" href="javascript:initRequiredTask('<cfoutput>#termId#</cfoutput>','<cfoutput>#studentId#</cfoutput>');"><i class="mrs img btnPublish"></i><span class="uiButtonText">自动预置必修课</span></a>
								<a class="uiButton" href="<cfoutput>#buildURL('applyWizardByStudent', targetArgs)#</cfoutput>"><i class="mrs img btnAdd"></i><span class="uiButtonText">添加指定课程</span></a>
							</div>
							<h3><cfoutput>#academicYear#-#academicTerm#</cfoutput> 学期 学生选课情况</h3>
							<p>下列是本轮次选课安排中, 该学生所有已选课程的清单.</p>
							<hr/>
						</div>

						<div id="choosenCourse">
							<!--- 显示选课记录--->
							<!-- choosenCourse -->
							<cfoutput>#event.getArg("choosenCourse")#</cfoutput>
							<!-- /choosenCourse -->
						</div>
					
						<!---<div id="out"></div>--->
					</div>
				
					<div id="CourseTable" class="tabContent">
					
						<div class="noticeBlock">
							<h3><cfoutput>#academicYear#-#academicTerm#</cfoutput> 学期 学生课表</h3>
							<p>下列是本轮次选课, 该学生所有已选课程的课表安排.</p>
							<hr/>
						</div>
					
						<div id="choosenCourseTable">
							<!--- 显示课表--->
							<!-- choosenCourseTable -->
							<cfoutput>#event.getArg("choosenCourseTable")#</cfoutput>
							<!-- /choosenCourseTable -->
						</div>
					</div>
				
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						function initRequiredTask(termId, stuId) {
							
							/* 显示阻挡信息 */
							$.blockUI({ 
										message: '正在生成必修课表...',
										css: { 
												'width': '16%',
												'left': '42%',
												'border': 'none', 
												'padding': '15px 5px', 
												'backgroundColor': '#900', 
												'border-radius': '4px', 
												'opacity': .8, 
												'color': '#fff',
												'cursor': null
												},
										overlayCSS: {
												'backgroundColor': '#000', 
												'opacity': .1 ,
												'cursor': null
												}
										}); 
						
							/* 异步提交待选数据 */
							$.post(
									"<cfoutput>#buildURL('apiInitRequiredCourse')#</cfoutput>", 
									{
										'STU': stuId,
										'TID': termId,
										'seed': (new Date()).getTime()
									},
									function(data) {
										
										//$("#out").html(data);
										result = $.parseJSON(data);
										
										if ( result.success ) {
											
											/* 更新学生课表 */
											$.post(
													"<cfoutput>#buildURL('apiChoosenCourseTable')#</cfoutput>", 
													{
														'TID': '<cfoutput>#termId#</cfoutput>',
														'STU': '<cfoutput>#studentId#</cfoutput>',
														'seed': (new Date()).getTime()
													},
													function(tableData) {
														$("#choosenCourseTable").html(tableData);
													});
											
											/* 更新学生选课记录 */
											$.post(
													"<cfoutput>#buildURL('apiChoosenCourse')#</cfoutput>", 
													{
														'TID': '<cfoutput>#termId#</cfoutput>',
														'STU': '<cfoutput>#studentId#</cfoutput>',
														'seed': (new Date()).getTime()
													},
													function(tableData) {
													
														$("#choosenCourse").html(tableData);
														
														/* 取消阻挡 */
														$.unblockUI();
														
													});
											
										}
										else {
											alert(result.reason);
											/* 取消阻挡 */
											$.unblockUI();
										}
										
									});

						}
						
						function removeTask(chooserId, courseId, stuId, termId, taskType, taskId) {
							
							/* 显示阻挡信息 */
							$.blockUI({ 
										message: '正在删除课程...',
										css: { 
												'width': '16%',
												'left': '42%',
												'border': 'none', 
												'padding': '15px 5px', 
												'backgroundColor': '#090', 
												'border-radius': '4px', 
												'opacity': .8, 
												'color': '#fff',
												'cursor': null
												},
										overlayCSS: {
												'backgroundColor': '#000', 
												'opacity': .1 ,
												'cursor': null
												}
										}); 
						
							/* 异步提交退课数据 */
							$.post(
									"<cfoutput>#buildURL('apiRemoveTask')#</cfoutput>", 
									{
										'STU': stuId,
										'TID': termId,
										'CID' : courseId,
										'TSK': taskId,
										'TT' : taskType,
										'SCC' : chooserId,
										'seed': (new Date()).getTime()
									},
									function(data) {
										
										//$("#out").html(data);
										result = $.parseJSON(data);
										
										if ( result.success ) {
										
											/* 更新学生课表 */
											$.post(
													"<cfoutput>#buildURL('apiChoosenCourseTable')#</cfoutput>", 
													{
														'TID': '<cfoutput>#termId#</cfoutput>',
														'STU': '<cfoutput>#studentId#</cfoutput>',
														'seed': (new Date()).getTime()
													},
													function(tableData) {
														$("#choosenCourseTable").html(tableData);
													});
										
											/* 更新学生选课记录 */
											$.post(
													"<cfoutput>#buildURL('apiChoosenCourse')#</cfoutput>", 
													{
														'TID': '<cfoutput>#termId#</cfoutput>',
														'STU': '<cfoutput>#studentId#</cfoutput>',
														'seed': (new Date()).getTime()
													},
													function(tableData) {
												
														$("#choosenCourse").html(tableData);
														
														/* 取消阻挡 */
														$.unblockUI();
														
													});
										}
										else {
											alert(result.reason);
											/* 取消阻挡 */
											$.unblockUI();
										}
										
									});
							
						}
						// -->
						//]]>
					</script>
			
				</cfif>
				
			</div>
		</li>
	</ul>
</div>